package risoe.syslab.fhnew.common;

/*
 * Copyright (c) 2012-2014, Technical University of Denmark (DTU)
 * All rights reserved.
 * 
 * The Flexhouse 2.0 platform ("this software") is licensed under the
 * BSD 3-clause license.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *   - Neither the name of DTU nor the names of its contributors may be used to
 *     endorse or promote products derived from this software without specific
 *     prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE TECHNICAL UNIVERSITY OF DENMARK BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import java.util.ArrayList;

public class SystemConstants {

  public static final int DEFAULT_RMIPORT=1099;
  
  /**
   * Enum defining the type of devices in the flexhouse platform.
   * TODO: Expand to rest of flexhouse platform (Currently only applicable for flexhouse3)
   */
  public static enum DeviceType{
	  // Sensors
	  Temperature("Temp", false),
	  CO2("CO2", false),
	  Humidity("Humidity", false),
	  AnalogMeasurement("AnalogMeasurement", false),
	  Motion("Motion", false),
	  Presence("Presence", false),
	  Brightness("Brightness", false),
	  Window("Window", false),
	  Door("Door", false),
	  Voltage("Voltage", false),
	  Current("Current", false),
	  Power("Power", false),
	  FlowTemperature("Flow Temperature", false),
	  ReturnFlowTemperature("Return Flow Temperature", false),
	  Flow("Flow", false),
	  FlowPressure("Flow Pressure", false),
	  Button("Button", false),
	  WindDirection("Winddir", false),
	  WindSpeed("Windspd", false),
	  Insolation("Insolation", false),
	  Electrical("Electrical", false),
	  
	  // Actuators
	  PowerControlledHeater("PowerHeater", true),
	  TemperatureControlledHeater("TempHeater", true),
	  PowerControlledAirCon("PowerAirCon", true),
	  TemperatureControlledAirCon("TempAirCon", true),
	  Switch("Switch", true),
	  Waterboiler("Waterboiler", true),
	  DimmableLight("DimmableLight", true),
	  Fridge("Fridge", true);
	  
	  
	  // The tag that an XML file should supply to mark a device as this type
	  public final String mTag;
	  
	  // A type indicating either a sensor(0) or an actuator(1)
	  public final boolean mIsActuator;
	  
	  DeviceType(String tag, boolean isActuator){
		  mTag = tag;
		  mIsActuator = isActuator;
	  }
  }

  
  /**
   * Method to get a devicetype from a tag specified in an XML file
   * @param tag for which a devicetype must be found
   * @return a devicetype
   * @throws Exception if the tag does not match any devicetype
   */
  public static DeviceType getDeviceType(String tag) throws IllegalArgumentException{
	  for (DeviceType type : DeviceType.values()){
		  if (type.mTag.equals(tag)){
			  return type;
		  }
	  }
	  throw new IllegalArgumentException("Invalid device type bearing tag: "+tag);
  }

  /**
   * @return a list of all supported sensor types
   */
  public static DeviceType[] getSupportedSensors(){
	  ArrayList<DeviceType> types = new ArrayList<DeviceType>();
	  for (DeviceType type : DeviceType.values()){
		  // Check for actuator
		  if (!type.mIsActuator){
			  types.add(type);
		  }
	  }
	  return (DeviceType[]) types.toArray();
  }
  
  /**
   * @return a list of all supported actuator types
   */
  public static DeviceType[] getSupportedActuators(){
	  ArrayList<DeviceType> types = new ArrayList<DeviceType>();
	  for (DeviceType type : DeviceType.values()){
		  // Check for actuator
		  if (type.mIsActuator){
			  types.add(type);
		  }
	  }
	  return (DeviceType[]) types.toArray();
  }
}

